#include "fstream.h"
#include "iomanip.h"

void test_char(ofstream& fout, char c)
{
  fout << setw(32) << setfill('_') << resetiosflags(ios::adjustfield) << c << endl;
  fout << setw(32) << setfill('_') << resetiosflags(ios::adjustfield) << setiosflags(ios::left) << c << endl;
  fout << setw(32) << setfill('_') << resetiosflags(ios::adjustfield) << setiosflags(ios::right) << c << endl;
  fout << setw(32) << setfill('_') << resetiosflags(ios::adjustfield) << setiosflags(ios::internal) << c << endl;
  fout << endl;
}

void test_string(ofstream& fout, char const* s)
{
  fout << setw(32) << setfill('_') << resetiosflags(ios::adjustfield) << s << endl;
  fout << setw(32) << setfill('_') << resetiosflags(ios::adjustfield) << setiosflags(ios::left) << s << endl;
  fout << setw(32) << setfill('_') << resetiosflags(ios::adjustfield) << setiosflags(ios::right) << s << endl;
  fout << setw(32) << setfill('_') << resetiosflags(ios::adjustfield) << setiosflags(ios::internal) << s << endl;
  fout << endl;
}

void test_int(ofstream& fout, int i, int flags)
{
  fout << setw(32) << setfill('_') << resetiosflags(ios::basefield|ios::adjustfield) << setiosflags(flags) << i << endl;
  fout << setw(32) << setfill('_') << resetiosflags(ios::basefield|ios::adjustfield) << setiosflags(flags|ios::left) << i << endl;
  fout << setw(32) << setfill('_') << resetiosflags(ios::basefield|ios::adjustfield) << setiosflags(flags|ios::right) << i << endl;
  fout << setw(32) << setfill('_') << resetiosflags(ios::basefield|ios::adjustfield) << setiosflags(flags|ios::internal) << i << endl;
  fout << endl;
}

void test_double(ofstream& fout, double d, int flags)
{
  fout << setw(32) << setfill('_') << resetiosflags(ios::floatfield|ios::adjustfield) << setiosflags(flags) << d << endl;
  fout << setw(32) << setfill('_') << resetiosflags(ios::floatfield|ios::adjustfield) << setiosflags(flags|ios::left) << d << endl;
  fout << setw(32) << setfill('_') << resetiosflags(ios::floatfield|ios::adjustfield) << setiosflags(flags|ios::right) << d << endl;
  fout << setw(32) << setfill('_') << resetiosflags(ios::floatfield|ios::adjustfield) << setiosflags(flags|ios::internal) << d << endl;
  fout << endl;
}

int main()
{
  ofstream fout("out.tofstream");

  char c = 'X';

  test_char(fout, c);

  char* s = "Hello world";

  test_string(fout, s);

  int i = 1234;

  test_int(fout, i, 0);
  test_int(fout, i, ios::oct);
  test_int(fout, i, ios::dec);
  test_int(fout, i, ios::hex);

  test_int(fout, i, ios::uppercase);
  test_int(fout, i, ios::uppercase|ios::oct);
  test_int(fout, i, ios::uppercase|ios::dec);
  test_int(fout, i, ios::uppercase|ios::hex);

  test_int(fout, i, ios::showbase);
  test_int(fout, i, ios::showbase|ios::oct);
  test_int(fout, i, ios::showbase|ios::dec);
  test_int(fout, i, ios::showbase|ios::hex);

  test_int(fout, i, ios::uppercase|ios::showbase);
  test_int(fout, i, ios::uppercase|ios::showbase|ios::oct);
  test_int(fout, i, ios::uppercase|ios::showbase|ios::dec);
  test_int(fout, i, ios::uppercase|ios::showbase|ios::hex);

  test_int(fout, i, ios::showpos);
  test_int(fout, i, ios::showpos|ios::oct);
  test_int(fout, i, ios::showpos|ios::dec);
  test_int(fout, i, ios::showpos|ios::hex);

  i = -1234;

  test_int(fout, i, 0);
  test_int(fout, i, ios::oct);
  test_int(fout, i, ios::dec);
  test_int(fout, i, ios::hex);

  test_int(fout, i, ios::uppercase);
  test_int(fout, i, ios::uppercase|ios::oct);
  test_int(fout, i, ios::uppercase|ios::dec);
  test_int(fout, i, ios::uppercase|ios::hex);

  test_int(fout, i, ios::showbase);
  test_int(fout, i, ios::showbase|ios::oct);
  test_int(fout, i, ios::showbase|ios::dec);
  test_int(fout, i, ios::showbase|ios::hex);

  test_int(fout, i, ios::showpos);
  test_int(fout, i, ios::showpos|ios::oct);
  test_int(fout, i, ios::showpos|ios::dec);
  test_int(fout, i, ios::showpos|ios::hex);

  double d = 123456789.123456789;

  test_double(fout, d, 0);
  test_double(fout, d, ios::fixed);
  test_double(fout, d, ios::scientific);

  test_double(fout, d, ios::uppercase);
  test_double(fout, d, ios::uppercase|ios::fixed);
  test_double(fout, d, ios::uppercase|ios::scientific);

  test_double(fout, d, ios::showpos);
  test_double(fout, d, ios::showpos|ios::fixed);
  test_double(fout, d, ios::showpos|ios::scientific);

  test_double(fout, d, ios::showpoint);
  test_double(fout, d, ios::showpoint|ios::fixed);
  test_double(fout, d, ios::showpoint|ios::scientific);

  d = -123456789.123456789;

  test_double(fout, d, 0);
  test_double(fout, d, ios::fixed);
  test_double(fout, d, ios::scientific);

  test_double(fout, d, ios::uppercase);
  test_double(fout, d, ios::uppercase|ios::fixed);
  test_double(fout, d, ios::uppercase|ios::scientific);

  test_double(fout, d, ios::showpos);
  test_double(fout, d, ios::showpos|ios::fixed);
  test_double(fout, d, ios::showpos|ios::scientific);

  test_double(fout, d, ios::showpoint);
  test_double(fout, d, ios::showpoint|ios::fixed);
  test_double(fout, d, ios::showpoint|ios::scientific);
}
